<?php
namespace app\index\controller;
//use PhpOffice\PhpSpreadsheet\Spreadsheet;
//use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Index
{
    public function index(){
        return view("",[
            "url"=>[]
        ]);
//        $spreadsheet = new Spreadsheet();
//        $sheet = $spreadsheet->getActiveSheet();
//        $sheet->setCellValue('A1', 'Hello World !');
//
//        $writer = new Xlsx($spreadsheet);
//        $writer->save('hello world.xlsx');
//        header('Content-Type: applicationnd.openxmlformats-officedocument.spreadsheetml.sheet');
//        header('Content-Disposition: attachment;filename="hello world.xlsx"');
//        $writer->save('php://output');
//        die;
         define("DI", "/www/thinkphp5/json/");
        define("DIF", "/www/thinkphp5/json/ff/");
        define("R", "\r\n");
        define("TB", "  ");
        $string='';
         file_put_contents(DIF.date("Y-m-d").".json", $string);
        $d=scandir(DI);
        foreach($d as $v){
            $file=DI.$v;
            if(! is_file($file)){
                continue;
            }
            $filedata= file_get_contents($file);
            $f= json_decode($filedata,true);
            $string .=R."//".TB.$f['name'] .R.TB;
            $this->b($string, $f['requests']);
            $string .=R.R.R."//==================================".R;
        }
        file_put_contents(DIF.date("Y-m-d").".txt_", $string);
        echo "<pre>";
        echo file_get_contents(DIF.date("Y-m-d").".json");
        
    }
    public function b(&$str,$requests){
//        print_r($requests);
        foreach($requests as $array){
            $str .=R.TB.TB;
            $str.="//接口地址：".$array['url'] .R.TB.TB;
            $str.="//接口名称：".$array['name'] .R.TB.TB;
            $str.="//请求方式：".$array['method'] .R.TB.TB;
            $str.="//请求参数：".R;
            if($array["method"] == "GET"){
                $str.= self::bx($array['queryParams']);
            } else {
                 $str.= self::bx( $array["data"] );
            }
            
            $str .=R.R.R."//++++++++++++++++++++++++++++++++".R;
        }
    }
    static function bx($array){
    if(empty($array) )return '//无';
        $str='{'.R;
        foreach($array as $aa){
            if(isset($aa['type']) && $aa['type'] =='file'){
                $type='file  ';
            }else{
                $type='string';
            }
            $str.=R."                         // 参数类型：". $type  .TB."参数解释：".$aa['description'].R;
            $str .="        " .$aa['key'] .":'". @$aa['value']."', ";
        }
        $str.=R."}";
        return $str;
    }
    
}
